package com.xjh.t.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xjh.t.common.Constast;
import com.xjh.t.common.DataGridView;
import com.xjh.t.domain.GroupInfo;
import com.xjh.t.domain.OperateLog;
import com.xjh.t.service.IOperateLogService;
import com.xjh.t.vo.GroupInfoVo;
import com.xjh.t.vo.OperateLogVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-03-29
 */
@RestController
@RequestMapping("/operatelog")
public class OperateLogController {

    @Autowired
    private IOperateLogService operateLogService;

    @RequestMapping("loadAllOperateLog")
    public DataGridView loadAllOperateLog(OperateLogVo vo) {

        IPage<OperateLog> page = new Page<>(vo.getPage(), vo.getLimit());
        QueryWrapper<OperateLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(vo.getOpUsername()), "op_username", vo.getOpUsername());
        queryWrapper.eq(vo.getOpType() != null && vo.getOpType() < Constast.OPERATE_TYPE.MAX.ordinal(), "op_type", vo.getOpType());

        queryWrapper.ge(vo.getStartTime() != null, "op_time", vo.getStartTime());
        queryWrapper.le(vo.getEndTime() != null, "op_time", vo.getEndTime());

        queryWrapper.orderByDesc("op_time");

        this.operateLogService.page(page, queryWrapper);

        return new DataGridView(page.getTotal(), page.getRecords());

    }
}

